class Array
  
  def shuffle
    sort_by{rand};
  end
  
  def pick_random
    self[rand(size)];
  end
  
end

class Word
  attr_reader :word;
  
  class << self

    private
    def add_next_letters_for(letter, *nexts)    
      next_letters = self.send(:class_variable_get, :@@next_letters);
      next_letters[letter.to_s] += nexts.flatten.map{|l| l.to_s;};
    end
  
  end
  
  Letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
  Consonants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"];
  Vowels = ["a", "e", "i", "o", "u"];
  
  @@next_letters = Hash.new([]);
  
  Consonants.each{|consonant| add_next_letters_for(consonant, Vowels);};
  Vowels.each{|vowel| add_next_letters_for(vowel, Consonants);};

  ["c", "l", "s"].each{|letter| add_next_letters_for(letter, "h");};
  add_next_letters_for "u", Vowels;

  def initialize(length=(rand(5)+1))
    @word = Consonants.pick_random; 
    length.times do
      last = @word[@word.size-1].chr;
      @word << @@next_letters[last].pick_random;
    end
    p @word
  end
  
  alias_method :to_s, :word;
  
end